<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:ry="">
	<head>
		<th:block th:include="include :: header('新增参数')" />
	</head>
	<body class="white-bg">
	    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
	        <form class="form-horizontal m" id="form-config-add" name="form-config-add">
	        <div class="form-group">
	            <label class="col-sm-3 control-label is-required">参数名称：</label>
	            <div class="col-sm-8">
	                <input id="configName" name="config_name" class="form-control" type="text" required>
	            </div>
	        </div>
	        <div class="form-group">
	            <label class="col-sm-3 control-label is-required">参数键名：</label>
	            <div class="col-sm-8">
	                <input id="configKey" name="config_key" class="form-control" type="text" required>
	            </div>
	        </div>
	        <div class="form-group">
	            <label class="col-sm-3 control-label is-required">参数键值：</label>
	            <div class="col-sm-8">
	                <input id="configValue" name="config_value" class="form-control" type="text" required>
	            </div>
	        </div>
	        <div class="form-group">
				<label class="col-sm-3 control-label is-required">系统内置：</label>
				<div class="col-sm-8">
				    <ry:radioDict dictType="sys_yes_no" name="config_type" class="radio-box" required="true"/>
				</div>
			</div>
			<div class="form-group">
	            <label class="col-sm-3 control-label">备注：</label>
	            <div class="col-sm-8">
	                <textarea id="remark" name="remark" class="form-control" style="height: 150px;"></textarea>
	            </div>
	        </div>
	    </form>
	    </div>
	    <th:block th:include="include :: footer" />
	    <script type="text/javascript">
		    var prefix = ctx + "system/param";

		    $("#form-config-add").validate({
		    	onkeyup: false,
		        rules: {
		            config_key: {
		                remote: {
		                    url: prefix + "/checkConfigKeyUnique",
		                    type: "post",
		                    dataType: "json",
		                    data: {
		                        "config_key": function() {
		                        	return $.common.trim($("#config_key").val());
		                        }
		                    },
		                    dataFilter: function(data, type) {
		                        return $.validate.unique(data);
		                    }
		                }
		            },
		        },
		        messages: {
		            "config_key": {
		                remote: "参数键名已经存在"
		            }
		        },
		        focusCleanup: true,
			    errorPlacement: function (error, element) { //指定错误信息位置
			      	if (element.is(':radio')) {//如果是radio
			       		error.appendTo(element.parent().parent().parent()); //将错误信息添加当前元素的父结点后面
			     	}
			     	else {
			       		error.insertAfter(element);
			     	}
			   	}
		    });

		    function submitHandler() {
		        if ($.validate.form()) {
		            $.operate.save(prefix + "/save", $('#form-config-add').serialize());
		        }
		    }
	    </script>
	</body>
</html>